package com.cy.pj.notice.service.impl;

import com.cy.pj.notice.pojo.SysNotice;
import com.cy.pj.notice.pojo.dao.SysNoticeDao;
import com.cy.pj.notice.service.SysNoticeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Service 注解由spring提供，
 * 一般用于描述分层架构中的业务逻辑对象，这样的类会交给spring管理
 */
@Service
public class SysNoticeServiceImpl implements SysNoticeService {

    /**
     * 创建日志门面API对象
     * 初始化日志对象（org.slf4j.*）
     * LoggerFactory：通过工厂创建日志对象
     */
    private static final Logger log=
            LoggerFactory.getLogger(SysNoticeServiceImpl.class);

    @Autowired
    private SysNoticeDao sysNoticeDao;

    //通过构造方法直接进行DI操作
    //@Autowired 可以省略
    /*public SysNoticeServiceImpl(SysNoticeDao sysNoticeDao){
        this.sysNoticeDao=sysNoticeDao;
    }*/

    @Override
    public List<SysNotice> findNotice(SysNotice sysNotice) {
        long t1 = System.currentTimeMillis();
        log.info("method start {}",t1);//这里的{}表示占位符
        List<SysNotice> list = sysNoticeDao.selectNotice(sysNotice);
        long t2 = System.currentTimeMillis();
        log.info("method end {}",t2);
        return list;
    }

    @Override
    public int saveNotice(SysNotice sysNotice) {
        int rows = sysNoticeDao.insertNotice(sysNotice);
        return rows;
    }

    @Override
    public SysNotice findById(Long... id) {
        SysNotice notice = sysNoticeDao.selectById(id);
        return notice;
    }

    @Override
    public int updateNotice(SysNotice sysNotice) {
        return sysNoticeDao.updateNotice(sysNotice);
    }

    @Override
    public int deleteById(Long... id) {
        int rows = sysNoticeDao.deleteById(id);
        return rows;
    }
}
